<template>
<div>
  <div :id="mixtureId" class="mixture"> </div>
</div>
</template>
<script>
let echarts = require("echarts");
export default {
  props: {
   mixtureId: {
      type: Object,
      default: function(){
        return {};
      }
    },
        xAxisData: {
      type: Array,
      default: [],
    },
    text: {
      type: String,
      default: "",
    },
    mixtureId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {};
  },
  watch: {
    MixtureData: {
      handler() {
        this.initChart();
      },
      deep: true,
    },
  },
  created() {},
  mounted() {
    var chartDom = document.getElementById(this.mixtureId);
    this.myHisLevelChart = echarts.init(chartDom);
    this.$nextTick(() => {
      this.initChart();
    });
    window.addEventListener("resize", this.initChart, false);
  },
  methods: {
    initChart() {
    this.myHisLevelChart.resize();
    var option = {
        tooltip: {
        trigger: 'axis',
        axisPointer: {
        type: 'cross',
        crossStyle: {
            color: '#999'
            }
          }
        },
        toolbox: {
            feature: {
            dataView: { show: true, readOnly: false },
            magicType: { show: true, type: ['line', 'bar'] },
            restore: { show: true },
            saveAsImage: { show: true }
            }
        },
      xAxis: [
          {
            type: "category",
            axisTick: {
              alignWithLabel: true,
            },
            data: this.xAxisData,
          },
        ],
      yAxis:[
          {
            type: "value",
            show: true,
            splitNumber: 10, //坐标轴的分割段数
            axisLabel: {
              fontSize: 14,
              color: "#333",
            },
            splitLine: {
              show: false, //是否显示分隔线。
            },
          },
          {
            type: "value",
            axisLabel: {
              fontSize: 14,
              color: "#333",
              formatter: "{value}",
            },
            splitLine: {
              show: false, //是否显示分隔线。
            },
          },
        ],
        // legend: this.MixtureData.legend, //标记属性
        // grid: this.MixtureData.grid, //绘图区调整
        // series: this.MixtureData.series,
      };
      this.myHisLevelChart.setOption(option, true);
    },
  },
  beforeDestroy() {
    window.removeEventListener("resize", this.initChart, false);
  },
};
//监听window窗口大小变化的事件
// window.onresize= function(){
//   echarts.resize()
// }
</script>
<style lang="scss" scoped>
  .mixture {
    margin-top: 100px;
    margin-left: 10%;
    width: 80%;
    height: 600px;
    border: 1px solid wheat;
    // height: 17rem;
  }
</style>
